{% import "TopxiaWebBundle:Common:data-dict-macro.html.twig" as dict_macro %}
{% extends 'TopxiaAdminBundle::layout.html.twig' %}

{% set script_controller = 'order/refunds' %}
{% set menu = 'admin_'~targetType~'_refunds_manage' %}

{% block main %}
  <form id="user-search-form" class="form-inline well well-sm" action="" method="get" novalidate>
    <div class="form-group">
      <select class="form-control" name="status">
        {{ select_options(dict('refundStatus'), app.request.get('status'), '退款状态'|trans) }}
      </select>
    </div>

    <div class="form-group">
      <input class="form-control" type="text" name="nickname" value="{{ app.request.get('nickname') }}" placeholder="{{'退款人用户名'|trans}}">
    </div>

{#     <div class="form-group" >
      <input class="form-control" type="text" name="courseId" value="{{ app.request.get('courseId') }}" placeholder="课程编号">
    </div> #}

    <div class="form-group">
      <input class="form-control" type="text" name="title" value="{{ app.request.get('title') }}" 
      {% if targetType == 'course' %}
      placeholder="{{'课程名'|trans}}"
      {% elseif targetType == 'classroom' %}
      placeholder="{{'班级名'|trans}}"
      {% endif %}
      >
    </div>

    <div class="form-group">
      <input class="form-control" type="text" name="orderSn" value="{{ app.request.get('orderSn') }}" placeholder="{{'订单号'|trans}}">
    </div>

    <button class="btn btn-primary">{{'搜索'|trans}}</button>

  </form>

  <table class="table table-striped table-hover" id="refunds-table">
    <thead>
      <tr>
        <th width="40%">{{'退款订单'|trans}}</th>
        <th>{{'订单成交金额'|trans}}</th>
        <th>{{'退款人'|trans}}</th>
        <th>{{'退款状态'|trans}}</th>
        <th>{{'操作人'|trans}}</th>
        <th>{{'操作'|trans}}</th>
      </tr>
    </thead>
    <tbody>
      {% if refunds %}
        {% for refund in refunds %}
          {% set order = orders[refund.orderId] %}
          {% set user = users[refund.userId] %}
          <tr>
            <td>
              {% if order.targetType == 'course' %}
                <a href="{{ path('course_show', {id:order.targetId}) }}" target="_blank">{{ order.title }}</a>
              {% elseif order.targetType == 'classroom' %}
                <a href="{{ path('classroom_show', {id:order.targetId}) }}" target="_blank">{{ order.title }}</a>
              {% else %}
                {{ order.title }}
              {% endif %}
              <div class="text-muted text-sm">{{'订单号：'|trans}}{{ order.sn }} | {{'成交时间：'|trans}}{{ order.createdTime|date('Y-n-d H:i') }}</div>
              <div class="text-muted text-sm">{{'退款理由：'|trans}}{{ refund.reasonNote }} | {{'退款时间：'|trans}}{{ refund.createdTime|date('Y-n-d H:i') }}</div>
            </td>
            <td>{{ order.amount }}{{'元'|trans}}</td>
            <td>
              {{ admin_macro.user_link(user) }}
            </td>
            <td>
              {{ dict_macro.refundStatus(refund.status) }}
              {% if refund.status == 'success' %}
                <div class="text-sm text-muted">{{'实退%actualAmount%元'|trans({'%actualAmount%': refund.actualAmount })}}</div>
              {% endif %}
            </td>
            <td>
              {% if refund.operator != 0 %}
                {{ admin_macro.user_link(users[refund.operator]) }}
              {% else %}
                --
              {% endif %}
            </td>
            <td>
              {% if refund.status == 'created' %}
                <button class="btn btn-sm btn-primary confirm-refund" type="button" data-target="#modal" data-toggle="modal" data-url="{{ path('admin_order_audit_refund', {id:order.id}) }}">{{'审核'|trans}}</button>
                <button class="btn btn-sm btn-default cancel-refund" type="button" data-url="{{ path('admin_order_cancel_refund', {id:order.id}) }}">{{'取消'|trans}}</button>
              {% endif %}
            </td>
          </tr>
        {% endfor %}
      {% else %}
        <tr><td colspan="20"><div class="empty">{{'暂无退款记录'|trans}}</div></td></tr>
      {% endif %}
    </tbody>
  </table>

  <div class="paginator">
    {{ admin_macro.paginator(paginator) }} 
  </div>
{% endblock %}
